﻿<Button @onclick="@OnClick">点击打开 Dialog</Button>

<Dialog></Dialog>

@code {
    /// <summary>
    /// 获得 DialogService 实例
    /// </summary>
    [Inject]
    private DialogService? DialogService { get; set; }

    /// <summary>
    /// 点击按钮调用 Dialog 服务
    /// </summary>
    /// <returns></returns>
    private Task OnClick()
    {
        DialogService?.Show(new DialogOption()
        {
            Title = "我是服务创建的弹出框",
            BodyTemplate = DynamicComponent.CreateComponent<Button>(new KeyValuePair<string, object>[]
            {
                new KeyValuePair<string, object>(nameof(Button.ChildContent), new RenderFragment(builder => builder.AddContent(0, "我是服务创建的按钮")))
            })
            .Render()
        });
        return Task.CompletedTask;
    }
}
